package com.ruoyi.tools.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tools.domain.TbToolsBorrow;
import com.ruoyi.tools.service.ITbToolsBorrowService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-01-12
 */
@Controller
@RequestMapping("/tools/borrow")
public class TbToolsBorrowController extends BaseController
{
    private String prefix = "tools/borrow";

    @Autowired
    private ITbToolsBorrowService tbToolsBorrowService;

    @RequiresPermissions("tools:borrow:view")
    @GetMapping()
    public String borrow()
    {
        return prefix + "/borrow";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("tools:borrow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbToolsBorrow tbToolsBorrow)
    {
        startPage();
        List<TbToolsBorrow> list = tbToolsBorrowService.selectTbToolsBorrowList(tbToolsBorrow);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("tools:borrow:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbToolsBorrow tbToolsBorrow)
    {
        List<TbToolsBorrow> list = tbToolsBorrowService.selectTbToolsBorrowList(tbToolsBorrow);
        ExcelUtil<TbToolsBorrow> util = new ExcelUtil<TbToolsBorrow>(TbToolsBorrow.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add(Long toolsId, ModelMap map)
    {
        TbToolsBorrow tbToolsBorrow = tbToolsBorrowService.selectTbToolsListByToolsId(toolsId);
        map.put("tbToolsBorrow", tbToolsBorrow);
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("tools:borrow:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbToolsBorrow tbToolsBorrow)
    {
        return toAjax(tbToolsBorrowService.insertTbToolsBorrow(tbToolsBorrow));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbToolsBorrow tbToolsBorrow = tbToolsBorrowService.selectTbToolsBorrowById(id);
        mmap.put("tbToolsBorrow", tbToolsBorrow);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("tools:borrow:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbToolsBorrow tbToolsBorrow)
    {
        return toAjax(tbToolsBorrowService.updateTbToolsBorrow(tbToolsBorrow));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("tools:borrow:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbToolsBorrowService.deleteTbToolsBorrowByIds(ids));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("tools:borrow:still")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @GetMapping( "/still")
    @ResponseBody
    public AjaxResult still(Long id)
    {
        return toAjax(tbToolsBorrowService.still(id));
    }
}
